/* components */
import ChatAIInputBar from '@src/component/business/BizChatPanel/chat/components/input-bar'
/* enum */
import { ComponentNameEnum } from '@src/component/business/BizChatPanel/chat/model/enum'
/* model */
import { OpenAIMessageItemType } from '@src/component/business/BizChatPanel/chat/model'
/* scss */
import '@src/component/business/BizChatPanel/chat/components/message-avatar/index.scss'
/* vue */
import { defineComponent, PropType } from 'vue'
/* util */
import { isNotUserMessage, isUserMessage } from '@src/component/business/BizChatPanel/chat/util'

import { getRootWindowInitData } from '@src/util/window'

import { getLocalesOssUrl } from '@src/util/assets'

const xiaoBaoIcon = getLocalesOssUrl('/xiao-bao-icon.png')

export type ChatAIMessageAvatarProps = {
  value: OpenAIMessageItemType;
}

export interface ChatAIMessageAvatarSetupState {
  
}

export enum ChatAIMessageAvatarEventEnum {
  Input = 'input'
}

export default defineComponent({
  name: ComponentNameEnum.ChatAIMessageAvatar,
  components: {
    [ChatAIInputBar.name]: ChatAIInputBar
  },
  emits: [
  ],
  props: {
    value: {
      type: Object as PropType<OpenAIMessageItemType>,
      default: () => ({})
    }
  },
  computed: {
    /** 
     * @description 是否是用户消息
    */
    isUserMessage(): boolean {
      return isUserMessage(this.value)
    },
    /** 
     * @description 是否不为用户消息
    */
    isNotUserMessage(): boolean {
      return isNotUserMessage(this.value)
    },
    loginUser(): Record<string, any> {
      const rootWindowInitData = getRootWindowInitData()
      return {
        head: rootWindowInitData?.user?.head || ''
      }
    },
    loginUserHead(): string {
      return this.loginUser.head
    }
  },
  methods: {
    
  },
  render() {
    return (
      <div class={ComponentNameEnum.ChatAIMessageAvatar}>
        
        {this.isUserMessage && (
          <el-image
            class="avatar"
            src={this.loginUserHead}
          />
        )}
        
        {this.isNotUserMessage && (
          <el-image
            class="avatar"
            src={xiaoBaoIcon}
          />
        )}
        
      </div>
    ) as any
  }
})
